      Subroutine WHENIGT(n,x,incx,itarget,index,nn)
      integer n,x(n),incx,itarget,index(n),nn
      nn=0
      DO 09999 i=1,n,incx
      if(x(i).GT.itarget)then
      nn=nn+1
      index(nn)=i
      endif
09999 CONTINUE
      return
      end
      Subroutine WHENEQ(n,x,incx,itarget,index,nn)
      integer n,x(n),incx,itarget,index(n),nn
      nn=0
      DO 09996 i=1,n,incx
      if(x(i).EQ.itarget)then
      nn=nn+1
      index(nn)=i
      endif
09996 CONTINUE
      return
      end
      Subroutine WHENNE(n,x,incx,itarget,index,nn)
      integer n,x(n),incx,itarget,index(n),nn
      nn=0
      DO 09993 i=1,n,incx
      if(x(i).NE.itarget)then
      nn=nn+1
      index(nn)=i
      endif
09993 CONTINUE
      return
      end
      Integer function cvmgt(i,j,lx)
      integer i,j
      logical lx
      if(lx)then
      cvmgt=i
      else
      cvmgt=j
      endif
      write(*,*)' cvmgt i,j,lx',i,j,lx
      return
      end
      Integer function Ismin(n,x,incx)
      integer n,incx
      doubleprecision x(n)
      nn=1
      DO 09990 i=incx+1,n,incx
      if(x(i).LT.x(nn))nn=i
09990 CONTINUE
      Ismin=nn
      return
      end
      Integer function Irmin(n,x,incx)
      integer n,incx
      real x(n)
      nn=1
      DO 09987 i=incx+1,n,incx
      if(x(i).LT.x(nn))nn=i
09987 CONTINUE
      Irmin=nn
      return
      end
      Integer function Ismax(n,x,incx)
      integer n,incx
      doubleprecision x(n)
      nn=1
      DO 09984 i=incx+1,n,incx
      if(x(i).GT.x(nn))nn=i
09984 CONTINUE
      Ismax=nn
      return
      end
      Integer function Irmax(n,x,incx)
      integer n,incx
      real x(n)
      nn=1
      DO 09981 i=incx+1,n,incx
      if(x(i).GT.x(nn))nn=i
09981 CONTINUE
      Irmax=nn
      return
      end
